﻿package {
	import fl.controls.Slider;
	import fl.events.SliderEvent;
	import flash.display.Sprite;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.geom.Rectangle;
	import idv.cjcat.stardust.common.clocks.SteadyClock;
	import idv.cjcat.stardust.common.renderers.Renderer;
	import idv.cjcat.stardust.twoD.renderers.DisplayObjectRenderer;
	
	public class StarParticles extends Sprite {
		
		private var emitter:StarEmitter;
		
		public function StarParticles() {
			stage.scaleMode = StageScaleMode.NO_SCALE;
			root.scrollRect = new Rectangle(0, 0, 640, 400);
			
			emitter = new StarEmitter(new SteadyClock(0.5));
			
			var container:Sprite = new Sprite();
			var renderer:Renderer =  new DisplayObjectRenderer(container);
			renderer.addEmitter(emitter);
			addChildAt(container, 1);
			
			slider.addEventListener(SliderEvent.CHANGE, changeTimescale);
			
			addEventListener(Event.ENTER_FRAME, mainLoop);
		}
		
		private function mainLoop(e:Event):void {
			emitter.point.x = mouseX;
			emitter.point.y = mouseY;
			emitter.step();
		}
		
		private function changeTimescale(e:SliderEvent):void {
			emitter.stepTimeInterval = Slider(e.target).value; 
		}
	}
}